import Vue from "vue";
import VueRouter from "vue-router";
import store from "../store/index";

import Index from "../views/index.vue";
import Homepage from "../views/home/homepage.vue";

import Centre from "../views/center/Centre.vue";
import cenPurse from "../views/center/center//cenPurse/cenPurse.vue";
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: () => import("../views/login"),
  },
  {
    path: "/agesign",
    component: () => import("../views/signin/agesign.vue"),
  },
  {
    path: "/firmsign",
    component: () => import("../views/signin/firmsign.vue"),
  },
  {
    path: "/Centre",
    component: Centre,
    children: [
      {
        path: "/Centre",
        component: cenPurse,
      },
      // 我的简历
      {
        path: "/Centre/cenJane",
        component: () => import("../views/center/center/cenJane/cenJane.vue"),
      },
      // 我的收藏
      {
        path: "/Centre/cenCollect",
        component: () => import("../views/center/center/cenCollect/cenCollect.vue"),
      },
      // 我的订单
      {
        path: "/Centre/cenOrder",
        component: () => import("../views/center/center/cenOrder/cenOrder.vue"),
      },
      // 我的消息
      {
        path: "/Centre/cenMessage",
        component: () => import("../views/center/center/cenMessage/cenMessage.vue"),
      },
      // 我的邀请
      {
        path: "/Centre/cenInvite",
        component: () => import("../views/center/center/cenInvite/cenInvite.vue"),
      },
      // 我的发票
      {
        path: "/Centre/cenInvoice",
        component: () => import("../views/center/center/cenInvoice/cenInvoice.vue"),
      },
      // 投诉管理
      {
        path: "/Centre/cenPlain",
        component: () => import("../views/center/center/cenPlain/cenPlain.vue"),
      },
      // 账号管理
      {
        path: "/Centre/cenAccount",
        component: () => import("../views/center/center/cenAccount/cenAccount.vue"),
      },
      // 身份验证
      {
        path: "/Centre/cenStanding",
        component: () => import("../views/center/center/cenStanding/cenStanding.vue"),
      },
    ],
  },
  {
    path: "/",
    component: Index,
    children: [
      {
        path: "",
        component: Homepage,
      },
      // 推荐
      {
        path: "/commend",
        component: () => import("../views/Recommended/commend.vue"),
      },
      // 找帮帮
      {
        path: "/help",
        component: () => import("../views/help/help.vue"),
      },
      // 常见问题
      {
        path: "/problem",
        component: () => import("../views/problem/problem.vue"),
      },
      // 知识区
      {
        path: "/knowledge",
        component: () => import("../views/problem/knowledge.vue"),
      },
      // 活动
      {
        path: "/events",
        component: () => import("../views/events/events.vue"),
      },
    ],
  },
];

// 新添加的-解决导航重复点击报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const router = new VueRouter({
  routes,
});

// 切换路由之前 导航守卫  路由拦截
// router.beforeEach((to, from, next) => {
//   console.log(to.path, '导航守卫')
//   console.log(to)
//   var token = ''
//   var info = JSON.parse(localStorage.getItem('rabbitstore-client'))
//   if (info) {
//     token = info.user.userInfo.token
//   }
//   if (to.path == '/login') {
//     next()
//   } else {
//     if (token) {
//       next()
//     } else {
//       // next('/login')
//       //var aa = localStorage.getItem('xxx')
//       // if ((to.path == "/login" && aa)||(to.path == "/login/" && aa)) {
//       if (to.path == "/login/" || to.path == "/login") {
//         next()
//       } else {
//         next('/login')
//       }
//     }
//   }
// })

export default router;
